package cn.laixueit.service;

import cn.laixueit.mapper.EasyMapper;
import cn.laixueit.pojo.Easy;
import cn.laixueit.utils.Commons;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class EasyService {

    @Autowired
    private EasyMapper easyMapper;

    public PageInfo<Easy> findall(Integer startpage, Integer pagesize, Easy easy){
        PageHelper.startPage(startpage,pagesize);
        List<Easy> list = easyMapper.findall();
        PageInfo<Easy> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    public void add(Easy easy) {
        easy.setId(Commons.getuuid());
        easyMapper.add(easy);
    }

    public Easy findById(String id){
        try {
            Easy easy = easyMapper.findById(id);
            return easy;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public void update(Easy easy) {
        easyMapper.update(easy);
    }

    public void deleteById(String id) {
        easyMapper.deleteById(id);
    }
}
